﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter06
{
    public class Code08
    {
        private delegate string ReadLineDelegate();

        public static void Begin()
        {

            //1 1没有返回值，2数组参数必须是最后一项
            //2
            {
                string[] args = new string[2] { "save", "clear" };
                if (args.Length != 2)
                {
                    Console.WriteLine("Two arguments required.");
                    return;
                }
                string par1 = args[0];
                int par2 = Convert.ToInt32(args[1]);
                Console.WriteLine("String parameter: {0}", par1);
                Console.WriteLine("Interger parameter: {0}", par2);
                Console.ReadLine();
            }
            //3
            {
                ReadLineDelegate readLine = new ReadLineDelegate(Console.ReadLine);
                Console.WriteLine("Tpye a string:");
                string userInput = readLine();
                Console.WriteLine("You typed: {0}", userInput);
                Console.ReadLine();
            }
            //4 详见Order结构
            //5 详见Order结构
        }
    }

    public struct Order
    {
        public string itemName;
        public int unitCount;
        public double unitCost;

        public double TotalCost()
        {
            return unitCount * unitCost;
        }

        public string Info()
        {
            return "Order information: " + unitCount.ToString() + " " + itemName + " items at $" + unitCost.ToString() + " each, total cost $" + TotalCost().ToString();
        }
    }
}
